var Ajax;
if (Ajax && (Ajax != null)) {
	Ajax.Responders.register({
	  onCreate: function() {
        if($('spinner') && Ajax.activeRequestCount>0)
          Effect.Appear('spinner',{duration:0.5,queue:'end'});
	  },
	  onComplete: function() {
        if($('spinner') && Ajax.activeRequestCount==0)
          Effect.Fade('spinner',{duration:0.5,queue:'end'});
	  }
	});
}


function setAnswer(assignmentId, itemOptionId) {
	new Ajax.Request('/assessment/main/setAnswer',{asynchronous:true,evalScripts:false,parameters:'assignmentItemId=' + assignmentId + '&itemOptionId=' + itemOptionId});
}

function addAnswer(assignmentId, itemOptionId) {
	new Ajax.Request('/assessment/main/addAnswer',{asynchronous:true,evalScripts:false,parameters:'assignmentItemId=' + assignmentId + '&itemOptionId=' + itemOptionId});
}

function removeAnswer(assignmentId, itemOptionId) {
	new Ajax.Request('/assessment/main/removeAnswer',{asynchronous:true,evalScripts:false,parameters:'assignmentItemId=' + assignmentId + '&itemOptionId=' + itemOptionId});
}


// helper
function addCategory(element) {
	var category = prompt("Add new category:");
	if(category) {
		var o = document.createElement("option");
		var t = document.createTextNode(category);
		o.setAttribute("value",category);
		o.appendChild(t);
		
		element.appendChild(o);
		element.value = category; 
	}
	return false;
}



// UI
/*
 Initialize and render the MenuBar when its elements are ready 
 to be scripted.
 */
YAHOO.util.Event.onContentReady("appmenu", function() {

	/*
	 Instantiate a MenuBar:  The first argument passed to the 
	 constructor is the id of the element in the page 
	 representing the MenuBar; the second is an object literal 
	 of configuration properties.
	 */
	var oMenuBar = new YAHOO.widget.MenuBar("appmenu", {
		autosubmenudisplay : true,
		hidedelay : 750,
		lazyload : true
	});

	/*
	 Call the "render" method with no arguments since the 
	 markup for this MenuBar instance is already exists in 
	 the page.
	 */
	oMenuBar.render();
});